<template>
    <layout>
        <div class="page-field">
            <div class="page-part">
                <mt-field label="手机号" placeholder="请输入手机号" v-model="mobile"></mt-field>
                <mt-field label="验证码" placeholder="输入验证码" v-model="code">
                    <mt-button size="small" @click="send">发送验证码</mt-button>
                </mt-field>
            </div>

            <mt-button type="primary" size="large" @click="login">登录</mt-button>
        </div>
    </layout>
</template>
<style lang="scss">
    @import "index";
    .page-field{
        padding: 10px;
    }
</style>
<script type="text/babel">
    import { api } from 'framework/config.js';
    import Layout from "component/layout/standard";

    import Vue from 'vue'
    import Mint from 'mint-ui';
    Vue.use(Mint);

    export default {
        components: {
            Layout
        },
        data(){
            return {
                mobile: '18286140088',
                code: '8888'
            }
        },
        computed: {
            api(){
                return api();
            }
        },
        methods: {
            send(){
                if (!this.mobile){
                    Mint.Toast('手机号码不能为空');
                    return;
                }

                let param = new URLSearchParams();
                param.append("mobile", this.mobile);
                this.$http.post('/sms/send',
                    param
                ).then((response) => {
                    if (response.status == 200){
                        let data = response.data;
                        if (data.code == 200) {
                            Mint.Toast('发送成功');
                        }else{
                            Mint.Toast(data.message);
                        }
                    }else{
                    }
                });
            },
            login(){
                if (!this.mobile){
                    Mint.Toast('手机号码不能为空');
                    return;
                }

                if (!this.code){
                    Mint.Toast('验证码不能为空');
                    return;
                }
                let param = new URLSearchParams();
                param.append("mobile", this.mobile);
                param.append("code", this.code);
                this.$http.post('/login',
                    param
                ).then((response) => {
                    if (response.status == 200){
                        let data = response.data;
                        if (data.code == 200) {
                            Mint.Toast('登录成功');
                            window.location.href = "/index";
                        }else{
                            Mint.Toast(data.message);
                        }
                    }else{
                    }
                });
            }
        },
        created(){
        },
        mounted() {
        }
    }
</script>

